<script>
	import t from './common/helper.js';
	let openid = "";
	let appid = "wx483e4e7167d7be7c"; //appid
	let secret = "4919a2aa6d4db7494a55a1ed5eebeba3"; //AppSecret
	export default {
		methods: {
			login() {
				uni.login({
					onlyAuthorize: true,
					success: res => {
						let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret +
							'&js_code=' +res.code + '&grant_type=authorization_code';
						uni.request({
							url: url,
							success: res => {
								openid = res.data.openid;
								uni.setStorageSync('openid', openid);
								this.getUser(openid);
							}
						})
					}
				})
			},
			getUser(openid) {
				uni.request({
					url: `${t.o}/master`,
					method: "POST",
					data: {
						openid: openid, 
					},
					success: res => {
						try {
							uni.setStorageSync('user', res.data.data);
							console.log('储存成功');
						} catch (e) {
							console.log(e);
						}
					}
				})
			}
		},
		async created() {
		  await	this.login();
			uni.hideTabBar();
		},
		globalData: {
			imService: null,
			$upload: false,
			$uploadimg: false,
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import './static/font/font.css';
	@import './static/fonts/light/stylesheet.css';

	* {
		font-family: 'Montserrat_Light' !important;
	}

	html,
	body {
		background-color: #000000;
		color: #FFFFFF;
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		font-family: 'Montserrat_Light' !important;

		.content {
			height: 100%;
		}

	}
</style>
